 function SubmitForm(){
    //$('#response').html("<img src='img/ajax-loader.gif'>");
      
    $.ajax({
        type: "GET",
        async   : false,
        url: "validate.jsp",
        data: "username="+$("#username").val()+"&password="+$("#password").val()+"&email="+$("#email").val(),
        success: function(resp) {
            if(resp==1){
                $('#response').html("Username already exists");
                $("#username").val('');
                $("#password").val('');
                $("#email").val('');
                $("#retype_password").val('');

            } else if(resp==0){
                $('#response').html("You are registered succesfully, enjoy! We direct you to index page..");
                window.location.href="login.jsp";
            }
        }
    });

}

function Submit(){
    $('#response').html("<img src='img/ajax-loader.gif'>");
    $.ajax({
        type: "GET",
        async   : false,
        url: "getArticles.jsp",
        data: "q="+$("#hidden").val(),
        success: function(resp) {
            $('#response').html(resp);
        }
    });


}

function ClearHidden(){
    if($("#suggest13").val()=="")
        $("#hidden").val('');
}


function show( id){

    var url;
    showLoading();
        //load selected section
        switch(id){
            case "ua":
                url="getUsersActiveTranslations.jsp";
                break;
            case "up":
                url="getUsersFinishedTranslations.jsp";
                break;
            case "aa":
                url="getAllActiveTranslations.jsp";
                break;
            case "ap":
                url="getAllFinishedTranslations.jsp";
                break;
            case "ri":
                url="getInvitations.jsp";
                break;
            case "rr":

                break;
            case "friends":

                break;
            case "us":
                
                break;
            case "hs":
                url="getScores.jsp";
            default:
                //hide loading bar if there is no selected section
                hideLoading();
                break;
        }
    $.ajax({
        type: "GET",
        async   : false,
        url: url,
        data: "username="+$("#username").val(),
        success: function(resp) {
            document.getElementById("content").innerHTML=resp;
            
        }
    });
}
//show loading bar
    function showLoading(){
        var loading = $("#loading");
	var content = $("#content");
        loading
        .css({
            visibility:"visible"
        })
        .css({
            opacity:"1"
        })
        .css({
            display:"block"
        })
    ;
    }
    //hide loading bar
    function hideLoading(){
        var loading = $("#loading");
	var content = $("#content");
        loading.fadeTo(1000, 0);
    }



function SaveTranslation(){
	$('#response').html("<img src='img/ajax-loader.gif'>");
	$.ajax({
		type: "GET",
		async   : false,
		url: "saveTranslation.jsp",
		data: "text="+$("#translated").val()+"&transId="+$("#transid").val(),
		success: function(resp) {
			$('#response').html(resp);
		}
	});


}
function SaveandQuitTranslation(){
	$('#response').html("<img src='img/ajax-loader.gif'>");
	$.ajax({
		type: "GET",
		async   : false,
		url: "saveandQuitTranslation.jsp",
		data: "text="+$("#translated").val()+"&transId="+$("#transid").val(),
		success: function(resp) {
			$('#response').html(resp);
                         window.location.href="mainPage.jsp";
		}
	});


}

function DoneTranslation(){
	$('#response').html("<img src='img/ajax-loader.gif'>");
	$.ajax({
		type: "GET",
		async   : false,
		url: "DoneTranslation.jsp",
		data: "text="+$("#translated").val()+"&transId="+$("#transid").val(),
		success: function(resp) {
			$('#response').html(resp);
                         window.location.href="mainPage.jsp";
		}
	});


}

function InvitePerson(){
        $('#response').html("<img src='img/ajax-loader.gif'>");
        var person=$("#invite").val();
	$.ajax({
		type: "GET",
		async   : false,
		url: "invite.jsp",
		data: "person="+$("#invite").val()+"&transID="+$("#transid").val(),
		success: function(resp) {
			$('#response').html("User " + person + " is invited");
		}
	});


}

function getRating(){
    //alert(test1rating4.value);
    var arr = document.getElementsByName('test1rating4');
    var rate;
    for(var i=0;i<arr.length;i++){
        if(arr[i].checked){
            rate=arr[i].value;
        }
    }

    $.ajax({
		type: "GET",
		async   : false,
		url: "insertRating.jsp",
		data: "rate="+rate+"&transID="+$("#transID").val(),
		success: function(resp) {
			
		}
	});
}
function accepted(){
        $.ajax({
		type: "GET",
		async   : false,
		url: "acceptInvitation.jsp",
		data: "&invID="+$("#invID").val(),
		success: function(resp) {
                    window.location.href="mainPage.jsp";
		}
	});

}
function rejected(){
        $.ajax({
		type: "GET",
		async   : false,
		url: "rejectInvitation.jsp",
		data: "&invID="+$("#invID").val(),
		success: function(resp) {
                    window.location.href="mainPage.jsp";
		}
	});

}